package com.helasasa.maxfunds.lineofcredit.cashloan.cameroon.screen.login.subview

import android.annotation.SuppressLint
import android.content.Context
import android.util.AttributeSet
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import com.helasasa.maxfunds.lineofcredit.cashloan.R

interface IKeyboardCameroonNumberListener {
    fun onClick(tid: String)
}

class KeyboardCameroonNumber : RelativeLayout {

    private var onItemClick: IKeyboardCameroonNumberListener? = null

    constructor(context: Context) : super(context) {
        initializeView(context)
    }

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
        initializeView(context)
    }

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
        initializeView(context)
    }

    @SuppressLint("NotifyDataSetChanged")
    private fun initializeView(context: Context) {
        inflate(context, R.layout.view_cameroon_keyboard_number, this)

        findViewById<TextView>(R.id.code0).setOnClickListener {
            onItemClick?.onClick("0")
        }

        findViewById<TextView>(R.id.code1).setOnClickListener {
            onItemClick?.onClick("1")
        }

        findViewById<TextView>(R.id.code2).setOnClickListener {
            onItemClick?.onClick("2")
        }

        findViewById<TextView>(R.id.code3).setOnClickListener {
            onItemClick?.onClick("3")
        }

        findViewById<TextView>(R.id.code4).setOnClickListener {
            onItemClick?.onClick("4")
        }

        findViewById<TextView>(R.id.code5).setOnClickListener {
            onItemClick?.onClick("5")
        }

        findViewById<TextView>(R.id.code6).setOnClickListener {
            onItemClick?.onClick("6")
        }

        findViewById<TextView>(R.id.code7).setOnClickListener {
            onItemClick?.onClick("7")
        }

        findViewById<TextView>(R.id.code8).setOnClickListener {
            onItemClick?.onClick("8")
        }

        findViewById<TextView>(R.id.code9).setOnClickListener {
            onItemClick?.onClick("9")
        }

        findViewById<ImageView>(R.id.delete).setOnClickListener {
            onItemClick?.onClick("-1")
        }

        findViewById<ImageView>(R.id.dismiss).setOnClickListener {
            onItemClick?.onClick("-2")
        }
    }

    fun setListener(listener: IKeyboardCameroonNumberListener?) {
        this.onItemClick = listener
    }
}